﻿using System;
using System.Collections.Generic;

namespace RexToy.UI.WinForm.Controls
{
    public class FormMenu : System.Windows.Forms.MenuStrip
    {
        private const string MN_MDILIST = "mnMdiList";

        public virtual void Initialize()
        {
            SetMdiListItem();
        }

        private void SetMdiListItem()
        {
            var f = this.FindForm();
            if (f.IsMdiContainer)
            {
                var items = f.MainMenuStrip.Items.Find(MN_MDILIST, true);
                switch (items.Length)
                {
                    case 0:
                        break;

                    case 1:
                        var mdiListItem = items[0] as System.Windows.Forms.ToolStripMenuItem;
                        Assertion.IsNotNull(mdiListItem, "Mdi item is null.");
                        this.MdiWindowListItem = mdiListItem;
                        break;

                    default:
                        Assertion.Fail("More than 2 items named [mnMdiList] in main menu.");
                        break;
                }
            }
        }
    }
}
